package com.wsoft.bpm.controller;

import com.wsoft.bpm.query.run.ApprovalMessageQuery;
import com.wsoft.bpm.service.IActApprovalMessageService;
import com.wsoft.core.exception.Asserts;
import com.wsoft.response.ResponsePage;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 工作流审批语表 前端控制器
 *
 * @author zhonglj
 * @since 2024年12月21日 15:48:58
 */
@RestController
@RequestMapping("/approval/message")
public class ActApprovalMessageController {
    @Resource
    private IActApprovalMessageService approvalMessageService;

    @Operation(summary = "分页列表", description = "分页列表审批意见")
    @PostMapping("/pageList")
    public ResponseResult pageList(@RequestBody ApprovalMessageQuery query) {
        return ResponseResult.success(ResponsePage.restPage(approvalMessageService.pageList(query)));
    }

    @Operation(summary = "详情", description = "审批意见详情")
    @GetMapping("/detail")
    public ResponseResult detail(Long id) {
        return ResponseResult.success(approvalMessageService.detail(id));
    }

    @Operation(summary = "新增", description = "新增审批意见")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody ApprovalMessageQuery query) {
        approvalMessageService.insert(query);
        return ResponseResult.success("");
    }

    @Operation(summary = "更新", description = "更新审批意见")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody ApprovalMessageQuery query) {
        if (query.getId() == null) {
            Asserts.fail("主键id不能为空!");
        }
        approvalMessageService.update(query);
        return ResponseResult.success("");
    }

    @Operation(summary = "删除", description = "删除审批意见")
    @GetMapping("/delete")
    public ResponseResult delete(Long id) {
        approvalMessageService.delete(id);
        return ResponseResult.success("");
    }
}
